package com.qianfeng.smartdevice.utils;



import com.qianfeng.smartdevice.pojo.SysUserInfo;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by wenka on 2022/3/25 14:19
 *
 * @author wenka
 * @version 1.0
 * @since 1.0
 */
public class SecurityUtils {
    public static SysUserInfo getLoginUser() {
       try {
           HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
           return (SysUserInfo) request.getSession().getAttribute("user");
       }catch (Exception e){
          e.printStackTrace();
       }
        return null;
    }
    public static SysUserInfo getLoginUserWithTest() {
        SysUserInfo sysUserInfo = new SysUserInfo();
        sysUserInfo.setUsername("zhangsan");
        return sysUserInfo;
    }
}
